<?php
namespace Home\Common;

class LoginLog extends Mysql{
	private $channelMembers;
	private $serverMembers;
	
	function __construct(){
		$this->channelMembers=array();
		$this->serverMembers=array();
		parent::__construct();
	}
	
	function getChannelLog(){
		//创建人数统计
		$date =	session('mog_thedate');
		
		$result	= $this->mysql->prepare("select channelid,count(distinct(userid)) from mog_user_info 
				where createtime = \"$date\" group by channelid");
		$result->execute();
		
		$createCount = array();
		while($row=$result->fetch(\PDO::FETCH_ASSOC)){
			$createCount[$row['channelid']] = array($row['count(distinct(userid))']);
		}
		
		//空账号人数统计
		
		$result = $this->mysql->prepare("select count(userid),channelid from mog_user_info 
				where level = 1 and createtime = \"$date\" and date = \"$date\" group by channelid");
		$result->execute();
		
		$nullUser = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			if(!isset($createCount[$row['channelid']][0]))  $createCount[$row['channelid']][0]=0;
			array_push($createCount[$row['channelid']],$row['count(userid)']);
		}
		
		//登录人数统计
		$result=$this->mysql->prepare("select channelid,count(distinct(userid)),count(userid) from mog_login 
				where date = \"$date\" group by channelid");
		$result->execute();
		
		$allCount = array();
		while($row = $result->fetch(\PDO::FETCH_ASSOC)){
			if(!isset($createCount[$row['channelid']][0])){  $createCount[$row['channelid']][0] = 0; $createCount[$row['channelid']][1]=0;}
			array_push($this->channelMembers,array($row['channelid'],$createCount[$row['channelid']][0],$row['count(distinct(userid))'],$row['count(userid)'],$createCount[$row['channelid']][1]));
		}
		
		return $this->channelMembers;
	}
	
	
	function getServerLog($date){
		$date	=	session('mog_thedate');
		//创建人数统计
		$result	=	$this->mysql->prepare("select serverid,count(distinct(userid)) from mog_user_info 
				where createtime = \"$date\" group by serverid");
		$result->execute();
		
		$createCount	=	array();
		while($row	=	$result->fetch(\PDO::FETCH_ASSOC)){
			$createCount[$row['serverid']]	=	array($row['count(distinct(userid))']);
		}
		
		//空账号人数统计
		
		$result	=	$this->mysql->prepare("select count(userid),serverid from mog_user_info 
				where level = 1  and channelid != 0 and createtime = \"$date\" and date = \"$date\" group by serverid");
		$result->execute();
		
		$nullUser	=	array();
		while($row	=	$result->fetch(\PDO::FETCH_ASSOC)){
			if(!isset($createCount[$row['serverid']][0]))  $createCount[$row['serverid']][0]=0;
			array_push($createCount[$row['serverid']],$row['count(userid)']);
		}
		
		//登录人数统计
		$result	=	$this->mysql->prepare("select serverid,count(distinct(userid)),count(userid) from mog_login 
				where date = \"$date\" group by serverid");
		$result->execute();
		
		$allCount	=	array();
		while($row	=	$result->fetch(\PDO::FETCH_ASSOC)){
			if(!isset($createCount[$row['serverid']][0])){  $createCount[$row['serverid']][0]=0; $createCount[$row['serverid']][1]=0;}
			array_push($this->serverMembers,array($row['serverid'],$createCount[$row['serverid']][0],$row['count(distinct(userid))'],$row['count(userid)'],$createCount[$row['serverid']][1]));
		}
		
		return $this->serverMembers;
	}
	
}
?>